package com.yc.hwc.web;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yc.hwc.bean.Result;
import com.yc.hwc.bean.TaskLog;
import com.yc.hwc.dao.ITaskLogDao;
import com.yc.hwc.dao.ITaskLogExDao;
import com.yc.util.Utils;

@RestController
@RequestMapping(path={"hwctask/taskLog","task/taskLog"})
public class TaskLogDo extends BaseAction<TaskLog> {

	@Resource
	ITaskLogDao itld;

	@PostMapping("myTaskList")
	public Result<?> myTaskList(@RequestBody TaskLog tl) {
		Long uid = Utils.nvl(tl.getInUser().getId(), 0l);
		Long tid = Utils.nvl(tl.getId(), 0l);
		return Result.success("个人作业查询成功", ((ITaskLogExDao) biz.getDao()).findTaskLog(uid, tid));
	}

	@PostMapping("taskDetail")
	public Result<?> taskDetail(@RequestBody long tid) {
		List<Map<String, Object>> list = ((ITaskLogExDao) biz.getDao()).findTaskLog(0, tid);
		return Result.success("个人作业查询成功", list.isEmpty() ? null : list.get(0));
	}

	@RequestMapping("clstask")
	public Result<?> clstask(String clsSn, @RequestParam(defaultValue = "0") int taskId) {
		return Result.success("班级作业查询成功", ((ITaskLogExDao) biz.getDao()).findByClsSnAndTaskId(clsSn, taskId));
	}

}
